package com.boot.web.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.log4j.Logger;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
public class BasePathInterceptor extends HandlerInterceptorAdapter {
private static Logger logger = Logger.getLogger(BasePathInterceptor.class);

public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        String scheme = request.getScheme();
        //logger.info("scheme="+scheme);
        String serverName = request.getServerName();
        //logger.info("服务名serverName="+serverName);
        int port = request.getServerPort();
        //logger.info("端口port="+port);
        String path = request.getContextPath();
        String basePath = scheme + "://" + serverName + ":" + port + path;
        logger.info("绝对路径："+basePath);
        request.setAttribute("root", basePath);
        return true;
    }

}
